﻿<!DOCTYPE HTML>
<html lang="zh-cn">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>人力资源管理系统-人事档案管理</title>
	<base href="/hrms/static">	
	<link href="plugins/bootstrap-3.3.0/css/bootstrap.min.css" rel="stylesheet"/>
	<link href="plugins/material-design-iconic-font-2.2.0/css/material-design-iconic-font.min.css" rel="stylesheet"/>
	<link href="plugins/bootstrap-table-1.11.0/bootstrap-table.min.css" rel="stylesheet"/>
	<link href="plugins/waves-0.7.5/waves.min.css" rel="stylesheet"/>
	<link href="plugins/jquery-confirm/jquery-confirm.min.css" rel="stylesheet"/>
	<link href="plugins/select2/css/select2.min.css" rel="stylesheet"/>

	<link href="css/common.css" rel="stylesheet"/>
</head>
<body>
<div id="main">
	<div id="toolbar">
		
		<a class="waves-effect waves-button" href="javascript:;" onclick="updateAction()"><i class="zmdi zmdi-edit"></i> 编辑员工信息</a>
		<a class="waves-effect waves-button" href="javascript:;" onclick="deleteAction()"><i class="zmdi zmdi-close"></i> 删除员工信息</a>
	</div>
	<table id="table"></table>
</div>
<!-- 修改 -->
<div id="createDialog" class="crudDialog" hidden>
	<form>
		<div class="form-group">
			<label for="input2">员工姓名</label>
			<input id="name" type="text" class="form-control">
		</div>
		<div class="form-group">
			<label for="input3">员工性别</label><br /><br /><br />
			<input type="radio" name="sex"/ value="男">男&emsp;
			<input type="radio" name="sex"/ value="女">女
		
		</div>
		<div class="form-group">
			<label for="input4">员工年龄</label>
			<input id="age" type="text" class="form-control">
		</div>
		<div class="form-group">
			<label for="input5">员工籍贯</label>
			<input id="place" type="text" class="form-control">
		</div>
		<div class="form-group">
			<label for="input6">员工生日</label>
			<input id="birth" type="text" class="form-control">
		</div>		
		<div class="form-group">
			<label for="input7">员工电话</label>
			<input id="tel" type="text" class="form-control">
		</div>		
		<div class="form-group">
			<label for="input8">员工所属部门</label>
			<input id="staff_department" type="text" class="form-control">
		</div>		
		<div class="form-group">
			<label for="input9">员工职位</label>
			<input id="staff_position" type="text" class="form-control">
		</div>				
		<div class="form-group">
			<label for="input10">员工入职时间</label>
			<input id="entry_time" type="text" class="form-control">
		</div>	
		<div class="form-group">
			<label for="input11">员工离职时间</label>
			<input id="leave_time" type="text" class="form-control">
		</div>							
	</form>
</div>

<script src="plugins/jquery.1.12.4.min.js"></script>
<script src="plugins/bootstrap-3.3.0/js/bootstrap.min.js"></script>
<script src="plugins/bootstrap-table-1.11.0/bootstrap-table.min.js"></script>
<script src="plugins/bootstrap-table-1.11.0/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="plugins/waves-0.7.5/waves.min.js"></script>
<script src="plugins/jquery-confirm/jquery-confirm.min.js"></script>
<script src="plugins/select2/js/select2.min.js"></script>

<script src="js/common.js"></script>
<script>
var $table = $('#table');
$(function() {
	$(document).on('focus', 'input[type="text"]', function() {
		$(this).parent().find('label').addClass('active');
	}).on('blur', 'input[type="text"]', function() {
		if ($(this).val() == '') {
			$(this).parent().find('label').removeClass('active');
		}
	});
	// bootstrap table初始化
	// http://bootstrap-table.wenzhixin.net.cn/zh-cn/documentation/
	$table.bootstrapTable({
		url: '/hrms/staff/listStaff',
		height: getHeight(),
		striped: true,
		search: true,
		searchOnEnterKey: true,
		showRefresh: true,
		showToggle: true,
		showColumns: true,
		minimumCountColumns: 2,
		showPaginationSwitch: true,
		clickToSelect: true,
		detailView: true,
		detailFormatter: 'detailFormatter',
		pagination: true,
		paginationLoop: false,
		classes: 'table table-hover table-no-bordered',
		//sidePagination: 'server',
		//silentSort: false,
		smartDisplay: false,
		idField: 'id',
		sortName: 'id',
		sortOrder: 'desc',
		escape: true,
		searchOnEnterKey: true,
		idField: 'systemId',
		maintainSelected: true,
		toolbar: '#toolbar',
		columns: [
			{field: 'state', checkbox: true},
			{field: 'name', title: '姓名', sortable: true, halign: 'center'},
			{field: 'sex', title: '性别', sortable: true, halign: 'center'},
			{field: 'age', title: '年龄', sortable: true, halign: 'center'},
			{field: 'place', title: '籍贯', sortable: true, halign: 'center'},
			{field: 'birth', title: '生日', sortable: true, halign: 'center'},
			{field: 'tel', title: '电话', sortable: true, halign: 'center'},
			{field: 'department_name', title: '部门', sortable: true, halign: 'center'},
			{field: 'position', title: '职位', sortable: true, halign: 'center'},
			{field: 'entry_time', title: '入职时间', sortable: true, halign: 'center'},
			{field: 'leave_time', title: '离职时间', sortable: true, halign: 'center'},
			{field: 'action', title: '操作', halign: 'center', align: 'center', formatter: 'actionFormatter', events: 'actionEvents', clickToSelect: false}
		]
	}).on('all.bs.table', function (e, name, args) {
		$('[data-toggle="tooltip"]').tooltip();
		$('[data-toggle="popover"]').popover();  
	});
});
function actionFormatter(value, row, index) {
    return [
        '<a class="like" href="javascript:void(0)" data-toggle="tooltip" title="添加"><i class="glyphicon glyphicon-heart"></i></a>　',
        '<a class="edit ml10" href="javascript:void(0)" data-toggle="tooltip" title="修改"><i class="glyphicon glyphicon-edit"></i></a>　',
        '<a class="remove ml10" href="javascript:void(0)" data-toggle="tooltip" title="删除"><i class="glyphicon glyphicon-remove"></i></a>'
    ].join('');
}

window.actionEvents = {
    'click .like': function (e, value, row, index) {
        alert('请在“入职管理”添加新员工！');
        console.log(value, row, index);
    },
    'click .edit': function (e, value, row, index) {
        updateAction();
        console.log(value, row, index);
    },
    'click .remove': function (e, value, row, index) {
        deleteAction();
        console.log(value, row, index);
    }
};
function detailFormatter(index, row) {
	var html = [];
	$.each(row, function (key, value) {
		html.push('<p><b>' + key + ':</b> ' + value + '</p>');
	});
	return html.join('');
}

// 编辑
function updateAction() {
	var rows = $table.bootstrapTable('getSelections');
	if (rows.length == 0) {
		$.confirm({
			title: false,
			content: '请至少选择一条记录！',
			autoClose: 'cancel|3000',
			backgroundDismiss: true,
			buttons: {
				cancel: {
					text: '取消',
					btnClass: 'waves-effect waves-button'
				}
			}
		});
	} else {
		
		
		
		
		$.confirm({
			type: 'blue',
			animationSpeed: 300,
			title: '编辑员工信息',
			content: $('#createDialog').html(),
			buttons: {
				confirm: {
					

					text: '确认',
					btnClass: 'waves-effect waves-button',
					action: function () {
						
						
						
						for(var i in rows){
							var staff={};
							staff.id=rows[i].id;
							staff.name = this.$content.find("#name").val();
							staff.sex = $("input[name='sex']:checked").val();
							staff.age = this.$content.find("#age").val();
							staff.place = this.$content.find("#place").val();
							staff.birth =this.$content.find("#birth").val();
							staff.tel = this.$content.find("#tel").val();
							staff.staff_department = this.$content.find("#staff_department").val();
							staff.staff_position = this.$content.find("#staff_position").val();
							staff.entry_time = this.$content.find("#entry_time").val();
							staff.leave_time = this.$content.find("#leave_time").val();
							
							
							
								$.ajax({
									dataType:"",
									async : true,
									url : "/hrms/staff/updateStaff",
									type : "POST",
									contentType : "application/json",
									data : JSON.stringify(staff),
									success : function(reslut) {

									console.log(reslut);
									
									}
								});
								
						
							
						
						}
						
						$.alert("编辑了"+rows.length+"条数据");
						
					}
		
				},
				cancel: {
					text: '取消',
					btnClass: 'waves-effect waves-button'
				}
			}
		});
	}
}
// 删除
function deleteAction() {
	var rows = $table.bootstrapTable('getSelections');
	if (rows.length == 0) {
		$.confirm({
			title: false,
			content: '请至少选择一条记录！',
			autoClose: 'cancel|3000',
			backgroundDismiss: true,
			buttons: {
				cancel: {
					text: '取消',
					btnClass: 'waves-effect waves-button'
				}
			}
		});
	} else {
		$.confirm({
			type: 'red',
			animationSpeed: 300,
			title: false,
			content: '确认删除该员工吗？',
			buttons: {
				confirm: {
					text: '确认',
					btnClass: 'waves-effect waves-button',
					action: function () {
						
						for(var i=rows.length-1;i>=0;i--){
							var staff={};
							staff.id=rows[i].id;
							
							console.log(staff);
								$.ajax({
									dataType:"",
									async : true,
									url : "/hrms/staff/deleteStaff",
									type : "POST",
									contentType : "application/json",
									data : JSON.stringify(staff),
									success : function(reslut) {

									console.log(reslut);
									
									}
								});
								$.alert("删除了"+rows.length+"条数据");
							 
							}
						
					}
				},
				cancel: {
					text: '取消',
					btnClass: 'waves-effect waves-button'
				}
			}
		});
	}
}
</script>
</body>
</html>